package com.kiln.juxingqs.ui

import android.view.ViewGroup
import client.global.commlib.base.SyBannerAdapter
import client.global.commlib.getScreenWidth
import com.bumptech.glide.request.RequestOptions
import com.kiln.juxingqs.R
import com.kiln.juxingqs.adapter.PpDetailAdapter
import com.kiln.juxingqs.databinding.ActivityPpdetailBinding
import com.kiln.juxingqs.ui.vm.TestViewModel
import com.kiln.juxingqs.BaseMiddleActivity
import com.kiln.juxingqs.api.bean.GoodsDetail
import com.youth.banner.indicator.CircleIndicator
import java.util.ArrayList

class PpDetailActivity : BaseMiddleActivity<TestViewModel, ActivityPpdetailBinding>() {

    override fun getLayout(): Int {
        return R.layout.activity_ppdetail
    }

    val adapter: PpDetailAdapter by lazy {
        PpDetailAdapter(this, mImgLoader)
    }

    override fun initView() {
        binding?.apply {
            event = this@PpDetailActivity
            recyclerView.adapter = adapter
        }
    }

    override fun initData() {
        var bannerList = intent.getParcelableArrayListExtra<GoodsDetail.Banner>("banner_list")!!
        var detailList = intent.getParcelableArrayListExtra<GoodsDetail.Detail>("detail_list")!!
        if (bannerList != null) {
            val width = getScreenWidth(this)
            val params: ViewGroup.LayoutParams = binding.banner.getLayoutParams()
            params.height = width //(width * 575 / 1400f).toInt()
            binding.banner.setLayoutParams(params)
            binding.banner.setIndicator(CircleIndicator(this))
            binding.banner.setAdapter(object : SyBannerAdapter<GoodsDetail.Banner>(bannerList) {
                override fun onBindView(
                    holder: BannerViewHolder?,
                    data: GoodsDetail.Banner?,
                    position: Int,
                    size: Int
                ) {
                    mImgLoader.load(data?.goods_img)
                        .apply(RequestOptions().error(R.mipmap.ic_launcher)).into(
                            holder!!.imageView
                        )
                }
            })
            binding.banner.start()
        }

        val list = ArrayList<String>()
        for (d in detailList!!) {
            list.add(d.goods_img)
        }

//        val list = ArrayList<Int>()
//        list.add(R.mipmap.z1)
//        list.add(R.mipmap.z2)
//        list.add(R.mipmap.z3)
//        list.add(R.mipmap.z4)
//        list.add(R.mipmap.z5)
//        list.add(R.mipmap.z6)
//        list.add(R.mipmap.z7)
//        list.add(R.mipmap.z8)
//        list.add(R.mipmap.z9)
//        list.add(R.mipmap.z10)
//        list.add(R.mipmap.z11)
//        list.add(R.mipmap.z12)

        adapter.submitList(list)
    }

    override fun initViewModel(): TestViewModel = createViewModel()

}